#include"dao_SDL.h"

DaoMethod* Dao_Get_Object_Method( DaoCData *cd, DValue *obj, const char *name )
{
  DaoMethod *meth;
  if( cd == NULL ) return NULL;
  obj->v.object = DaoCData_GetObject( cd );
  if( obj->v.object == NULL ) return NULL;
  obj->t = DAO_OBJECT;
  meth = DaoObject_GetMethod( obj->v.object, name );
  if( meth == NULL ) return NULL;
  if( meth->type != DAO_METAROUTINE && meth->type != DAO_ROUTINE ) return NULL;
  return meth;
}

static int Function_1000b( int *_cs, DaoMethod *_ro, DValue *_ob, SDL_RWops* self0 )
{
  const DValue _dao_nil = {0,0,0,0,{0}};
  DValue _dp[1] = { _dao_nil };
  DValue *_dp2[1] = { _dp+0 };
  DValue _res;
  DaoCData *_cd;
  DaoVmProcess *_vmp;
  int _close= (int)0;
  if( _ro == NULL ) goto EndCall;
  _dp[0] = DValue_WrapCData( dao_SDL_RWops_Typer, (void*) self0 );

  _ro = DaoMethod_Resolve( _ro, _ob, _dp2, 1 );
  if( _ro == NULL || _ro->type != DAO_ROUTINE ) goto EndCall;
  _vmp = DaoVmSpace_AcquireProcess( __daoVmSpace );
  if( (*_cs = DaoVmProcess_Call( _vmp, _ro, _ob, _dp2, 1 )) ==0 ) goto EndCall;
  _res = DaoVmProcess_GetReturned( _vmp );
  DaoVmSpace_ReleaseProcess( __daoVmSpace, _vmp );
  if( _res.t == DAO_INTEGER ) _close= (int) _res.v.i;

EndCall:
  DValue_ClearAll( _dp, 1 );
  return _close;
}

static int Function_1000a( int *_cs, DaoMethod *_ro, DValue *_ob, SDL_RWops* self0, const void* ptr, int size, int num )
{
  const DValue _dao_nil = {0,0,0,0,{0}};
  DValue _dp[4] = { _dao_nil, _dao_nil, _dao_nil, _dao_nil };
  DValue *_dp2[4] = { _dp+0, _dp+1, _dp+2, _dp+3 };
  DValue _res;
  DaoCData *_cd;
  DaoVmProcess *_vmp;
  int _write= (int)0;
  if( _ro == NULL ) goto EndCall;
  _dp[0] = DValue_WrapCData( dao_SDL_RWops_Typer, (void*) self0 );
  _dp[1] = DValue_WrapCData( NULL, (void*) ptr );
  _dp[2] = DValue_NewInteger( (int) size );
  _dp[3] = DValue_NewInteger( (int) num );

  _ro = DaoMethod_Resolve( _ro, _ob, _dp2, 4 );
  if( _ro == NULL || _ro->type != DAO_ROUTINE ) goto EndCall;
  _vmp = DaoVmSpace_AcquireProcess( __daoVmSpace );
  if( (*_cs = DaoVmProcess_Call( _vmp, _ro, _ob, _dp2, 4 )) ==0 ) goto EndCall;
  _res = DaoVmProcess_GetReturned( _vmp );
  DaoVmSpace_ReleaseProcess( __daoVmSpace, _vmp );
  if( _res.t == DAO_INTEGER ) _write= (int) _res.v.i;

EndCall:
  DValue_ClearAll( _dp, 4 );
  return _write;
}

static int Function_10008( int *_cs, DaoMethod *_ro, DValue *_ob, SDL_RWops* self0, int offset, int whence )
{
  const DValue _dao_nil = {0,0,0,0,{0}};
  DValue _dp[3] = { _dao_nil, _dao_nil, _dao_nil };
  DValue *_dp2[3] = { _dp+0, _dp+1, _dp+2 };
  DValue _res;
  DaoCData *_cd;
  DaoVmProcess *_vmp;
  int _seek= (int)0;
  if( _ro == NULL ) goto EndCall;
  _dp[0] = DValue_WrapCData( dao_SDL_RWops_Typer, (void*) self0 );
  _dp[1] = DValue_NewInteger( (int) offset );
  _dp[2] = DValue_NewInteger( (int) whence );

  _ro = DaoMethod_Resolve( _ro, _ob, _dp2, 3 );
  if( _ro == NULL || _ro->type != DAO_ROUTINE ) goto EndCall;
  _vmp = DaoVmSpace_AcquireProcess( __daoVmSpace );
  if( (*_cs = DaoVmProcess_Call( _vmp, _ro, _ob, _dp2, 3 )) ==0 ) goto EndCall;
  _res = DaoVmProcess_GetReturned( _vmp );
  DaoVmSpace_ReleaseProcess( __daoVmSpace, _vmp );
  if( _res.t == DAO_INTEGER ) _seek= (int) _res.v.i;

EndCall:
  DValue_ClearAll( _dp, 3 );
  return _seek;
}

static int Function_10009( int *_cs, DaoMethod *_ro, DValue *_ob, SDL_RWops* self0, void* ptr, int size, int maxnum )
{
  const DValue _dao_nil = {0,0,0,0,{0}};
  DValue _dp[4] = { _dao_nil, _dao_nil, _dao_nil, _dao_nil };
  DValue *_dp2[4] = { _dp+0, _dp+1, _dp+2, _dp+3 };
  DValue _res;
  DaoCData *_cd;
  DaoVmProcess *_vmp;
  int _read= (int)0;
  if( _ro == NULL ) goto EndCall;
  _dp[0] = DValue_WrapCData( dao_SDL_RWops_Typer, (void*) self0 );
  _dp[1] = DValue_WrapCData( NULL, (void*) ptr );
  _dp[2] = DValue_NewInteger( (int) size );
  _dp[3] = DValue_NewInteger( (int) maxnum );

  _ro = DaoMethod_Resolve( _ro, _ob, _dp2, 4 );
  if( _ro == NULL || _ro->type != DAO_ROUTINE ) goto EndCall;
  _vmp = DaoVmSpace_AcquireProcess( __daoVmSpace );
  if( (*_cs = DaoVmProcess_Call( _vmp, _ro, _ob, _dp2, 4 )) ==0 ) goto EndCall;
  _res = DaoVmProcess_GetReturned( _vmp );
  DaoVmSpace_ReleaseProcess( __daoVmSpace, _vmp );
  if( _res.t == DAO_INTEGER ) _read= (int) _res.v.i;

EndCall:
  DValue_ClearAll( _dp, 4 );
  return _read;
}

static void Function_10007( int *_cs, DaoMethod *_ro, DValue *_ob, void* self0, Uint8 stream[], int len )
{
  const DValue _dao_nil = {0,0,0,0,{0}};
  DValue _dp[3] = { _dao_nil, _dao_nil, _dao_nil };
  DValue *_dp2[3] = { _dp+0, _dp+1, _dp+2 };
  if( _ro == NULL ) return;
  _dp[0] = DValue_WrapCData( NULL, (void*) self0 );
  _dp[1] = DValue_NewVectorUI( (unsigned int*) stream, len );
  _dp[2] = DValue_NewInteger( (int) len );

  _ro = DaoMethod_Resolve( _ro, _ob, _dp2, 3 );
  if( _ro == NULL || _ro->type != DAO_ROUTINE ) return;
  DaoVmProcess *_vmp = DaoVmSpace_AcquireProcess( __daoVmSpace );
  *_cs = DaoVmProcess_Call( _vmp, _ro, _ob, _dp2, 3 );
  DaoVmSpace_ReleaseProcess( __daoVmSpace, _vmp );
  DValue_ClearAll( _dp, 3 );
}

SDL_ActiveEvent* Dao_SDL_ActiveEvent_New()
{
	SDL_ActiveEvent *self = calloc( 1, sizeof(SDL_ActiveEvent) );
	return self;
}

SDL_AudioCVT* Dao_SDL_AudioCVT_New()
{
	SDL_AudioCVT *self = calloc( 1, sizeof(SDL_AudioCVT) );
	return self;
}

Dao_SDL_AudioSpec* Dao_SDL_AudioSpec_New()
{
	Dao_SDL_AudioSpec *wrap = calloc( 1, sizeof(Dao_SDL_AudioSpec) );
	SDL_AudioSpec *self = (SDL_AudioSpec*) wrap;
	wrap->cdata = DaoCData_New( dao_SDL_AudioSpec_Typer, wrap );
	wrap->object = self;
	self->callback = Dao_SDL_AudioSpec_callback;
	self->userdata = wrap;
	return wrap;
}
/*
SDL_AudioSpec* Dao_SDL_AudioSpec_Wrap( SDL_AudioSpec *p )
{
	return p;
}
SDL_AudioSpec* Dao_SDL_AudioSpec_Copy( const SDL_AudioSpec p )
{
	SDL_AudioSpec *copy = malloc( sizeof( SDL_AudioSpec ) );
	memcpy( copy, & p, sizeof( SDL_AudioSpec ) );
	return copy;
}*/
static void Dao_SDL_AudioSpec_callback( void* self0, Uint8 stream[], int len )
{
  Dao_SDL_AudioSpec *self = (Dao_SDL_AudioSpec*) self0;
  SDL_AudioSpec *self2 = self->object;
  DaoCData *cdata = self->cdata;
  DaoVmProcess *vmproc = DaoVmSpace_AcquireProcess( __daoVmSpace );
  int _cs = 0;
  DValue _obj = {0,0,0,0,{0}};
  DaoMethod *_ro = Dao_Get_Object_Method( cdata, & _obj, "callback" );
  if( _ro ==NULL || _obj.t != DAO_OBJECT ) return;
  Function_10007( & _cs, _ro, & _obj, self0, stream, len );
}


SDL_CD* Dao_SDL_CD_New()
{
	SDL_CD *self = calloc( 1, sizeof(SDL_CD) );
	return self;
}

SDL_CDtrack* Dao_SDL_CDtrack_New()
{
	SDL_CDtrack *self = calloc( 1, sizeof(SDL_CDtrack) );
	return self;
}

SDL_Color* Dao_SDL_Color_New()
{
	SDL_Color *self = calloc( 1, sizeof(SDL_Color) );
	return self;
}

SDL_Cursor* Dao_SDL_Cursor_New()
{
	SDL_Cursor *self = calloc( 1, sizeof(SDL_Cursor) );
	return self;
}

SDL_Event* Dao_SDL_Event_New()
{
	SDL_Event *self = calloc( 1, sizeof(SDL_Event) );
	return self;
}

SDL_ExposeEvent* Dao_SDL_ExposeEvent_New()
{
	SDL_ExposeEvent *self = calloc( 1, sizeof(SDL_ExposeEvent) );
	return self;
}

SDL_JoyAxisEvent* Dao_SDL_JoyAxisEvent_New()
{
	SDL_JoyAxisEvent *self = calloc( 1, sizeof(SDL_JoyAxisEvent) );
	return self;
}

SDL_JoyBallEvent* Dao_SDL_JoyBallEvent_New()
{
	SDL_JoyBallEvent *self = calloc( 1, sizeof(SDL_JoyBallEvent) );
	return self;
}

SDL_JoyButtonEvent* Dao_SDL_JoyButtonEvent_New()
{
	SDL_JoyButtonEvent *self = calloc( 1, sizeof(SDL_JoyButtonEvent) );
	return self;
}

SDL_JoyHatEvent* Dao_SDL_JoyHatEvent_New()
{
	SDL_JoyHatEvent *self = calloc( 1, sizeof(SDL_JoyHatEvent) );
	return self;
}


SDL_KeyboardEvent* Dao_SDL_KeyboardEvent_New()
{
	SDL_KeyboardEvent *self = calloc( 1, sizeof(SDL_KeyboardEvent) );
	return self;
}

SDL_MouseButtonEvent* Dao_SDL_MouseButtonEvent_New()
{
	SDL_MouseButtonEvent *self = calloc( 1, sizeof(SDL_MouseButtonEvent) );
	return self;
}

SDL_MouseMotionEvent* Dao_SDL_MouseMotionEvent_New()
{
	SDL_MouseMotionEvent *self = calloc( 1, sizeof(SDL_MouseMotionEvent) );
	return self;
}

SDL_Overlay* Dao_SDL_Overlay_New()
{
	SDL_Overlay *self = calloc( 1, sizeof(SDL_Overlay) );
	return self;
}

SDL_Palette* Dao_SDL_Palette_New()
{
	SDL_Palette *self = calloc( 1, sizeof(SDL_Palette) );
	return self;
}

SDL_PixelFormat* Dao_SDL_PixelFormat_New()
{
	SDL_PixelFormat *self = calloc( 1, sizeof(SDL_PixelFormat) );
	return self;
}

SDL_QuitEvent* Dao_SDL_QuitEvent_New()
{
	SDL_QuitEvent *self = calloc( 1, sizeof(SDL_QuitEvent) );
	return self;
}

Dao_SDL_RWops* Dao_SDL_RWops_New()
{
	Dao_SDL_RWops *wrap = calloc( 1, sizeof(Dao_SDL_RWops) );
	SDL_RWops *self = (SDL_RWops*) wrap;
	wrap->cdata = DaoCData_New( dao_SDL_RWops_Typer, wrap );
	wrap->object = self;
	self->close = Dao_SDL_RWops_close;
	self->read = Dao_SDL_RWops_read;
	self->seek = Dao_SDL_RWops_seek;
	self->write = Dao_SDL_RWops_write;
	return wrap;
}
/*
SDL_RWops* Dao_SDL_RWops_Wrap( SDL_RWops *p )
{
	return p;
}
SDL_RWops* Dao_SDL_RWops_Copy( const SDL_RWops p )
{
	SDL_RWops *copy = malloc( sizeof( SDL_RWops ) );
	memcpy( copy, & p, sizeof( SDL_RWops ) );
	return copy;
}*/
static int Dao_SDL_RWops_close( SDL_RWops* self0 )
{
  Dao_SDL_RWops *self = (Dao_SDL_RWops*) self0;
  SDL_RWops *self2 = self->object;
  DaoCData *cdata = self->cdata;
  DaoVmProcess *vmproc = DaoVmSpace_AcquireProcess( __daoVmSpace );
  int _cs = 0;
  DValue _obj = {0,0,0,0,{0}};
  DaoMethod *_ro = Dao_Get_Object_Method( cdata, & _obj, "close" );
  int _close= (int)0;
  if( _ro ==NULL || _obj.t != DAO_OBJECT ) return _close;
  return (int)Function_1000b( & _cs, _ro, & _obj, self0 );
}
static int Dao_SDL_RWops_read( SDL_RWops* self0, void* ptr, int size, int maxnum )
{
  Dao_SDL_RWops *self = (Dao_SDL_RWops*) self0;
  SDL_RWops *self2 = self->object;
  DaoCData *cdata = self->cdata;
  DaoVmProcess *vmproc = DaoVmSpace_AcquireProcess( __daoVmSpace );
  int _cs = 0;
  DValue _obj = {0,0,0,0,{0}};
  DaoMethod *_ro = Dao_Get_Object_Method( cdata, & _obj, "read" );
  int _read= (int)0;
  if( _ro ==NULL || _obj.t != DAO_OBJECT ) return _read;
  return (int)Function_10009( & _cs, _ro, & _obj, self0, ptr, size, maxnum );
}
static int Dao_SDL_RWops_seek( SDL_RWops* self0, int offset, int whence )
{
  Dao_SDL_RWops *self = (Dao_SDL_RWops*) self0;
  SDL_RWops *self2 = self->object;
  DaoCData *cdata = self->cdata;
  DaoVmProcess *vmproc = DaoVmSpace_AcquireProcess( __daoVmSpace );
  int _cs = 0;
  DValue _obj = {0,0,0,0,{0}};
  DaoMethod *_ro = Dao_Get_Object_Method( cdata, & _obj, "seek" );
  int _seek= (int)0;
  if( _ro ==NULL || _obj.t != DAO_OBJECT ) return _seek;
  return (int)Function_10008( & _cs, _ro, & _obj, self0, offset, whence );
}
static int Dao_SDL_RWops_write( SDL_RWops* self0, const void* ptr, int size, int num )
{
  Dao_SDL_RWops *self = (Dao_SDL_RWops*) self0;
  SDL_RWops *self2 = self->object;
  DaoCData *cdata = self->cdata;
  DaoVmProcess *vmproc = DaoVmSpace_AcquireProcess( __daoVmSpace );
  int _cs = 0;
  DValue _obj = {0,0,0,0,{0}};
  DaoMethod *_ro = Dao_Get_Object_Method( cdata, & _obj, "write" );
  int _write= (int)0;
  if( _ro ==NULL || _obj.t != DAO_OBJECT ) return _write;
  return (int)Function_1000a( & _cs, _ro, & _obj, self0, ptr, size, num );
}

SDL_Rect* Dao_SDL_Rect_New()
{
	SDL_Rect *self = calloc( 1, sizeof(SDL_Rect) );
	return self;
}

SDL_ResizeEvent* Dao_SDL_ResizeEvent_New()
{
	SDL_ResizeEvent *self = calloc( 1, sizeof(SDL_ResizeEvent) );
	return self;
}

SDL_Surface* Dao_SDL_Surface_New()
{
	SDL_Surface *self = calloc( 1, sizeof(SDL_Surface) );
	return self;
}

SDL_SysWMEvent* Dao_SDL_SysWMEvent_New()
{
	SDL_SysWMEvent *self = calloc( 1, sizeof(SDL_SysWMEvent) );
	return self;
}




SDL_UserEvent* Dao_SDL_UserEvent_New()
{
	SDL_UserEvent *self = calloc( 1, sizeof(SDL_UserEvent) );
	return self;
}

SDL_VideoInfo* Dao_SDL_VideoInfo_New()
{
	SDL_VideoInfo *self = calloc( 1, sizeof(SDL_VideoInfo) );
	return self;
}



SDL_keysym* Dao_SDL_keysym_New()
{
	SDL_keysym *self = calloc( 1, sizeof(SDL_keysym) );
	return self;
}








